package com.dream.keigezhushou.Activity.kege.acty;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.dream.keigezhushou.Activity.Uiutils.UiUtils;
import com.dream.keigezhushou.Activity.kege.adapter.GiftRankingAdapter;
import com.dream.keigezhushou.Activity.pop.GiftPopCustomWindow;
import com.dream.keigezhushou.Activity.pop.GiftPopWindow;
import com.dream.keigezhushou.R;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 礼物榜
 */

public class GiftListActivity extends AppCompatActivity {


    @BindView(R.id.list_lv)
    PullToRefreshListView mPullToRefreshListView;
    @BindView(R.id.gift_ranking_send_linear)
    LinearLayout sendGift;
    @BindView(R.id.iv_return)
    ImageView ivReturn;
    @BindView(R.id.tv_title)
    TextView tvTitle;

    @BindView(R.id.gift_send_flowers_linear)
    LinearLayout sendFlowersLinear;

    @BindView(R.id.gift_send_flowers_makesure)
    Button sendBtn;


    @BindView(R.id.gift_send_flowers_mumber)
    EditText sendFlowersNumber;


    private ListView mListlv;
    private GiftRankingAdapter adapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gift_list);
        ButterKnife.bind(this);
        initView();
        onViewClick();
    }


    public void initView() {
        tvTitle.setText("礼物榜");
        sendFlowersLinear.setVisibility(View.GONE);
        mPullToRefreshListView.setMode(PullToRefreshBase.Mode.DISABLED);
        mListlv = mPullToRefreshListView.getRefreshableView();
        adapter = new GiftRankingAdapter(GiftListActivity.this);
        mListlv.setAdapter(adapter);
    }

    public void onViewClick() {

        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        sendGift.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                final GiftPopWindow giftPopWindow = new GiftPopWindow(View.inflate(GiftListActivity.this, R.layout.pop_gift_ranking, null), GiftListActivity.this, UiUtils.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT);
                giftPopWindow.showPopAtLocation(v, Gravity.BOTTOM);
                giftPopWindow.setItemListener(new GiftPopWindow.ItemClickListener() {
                    @Override
                    public void onClick() {

                    }

                    @Override
                    public void onSingDetail(View view) {
                        giftPopWindow.dismiss();

//                        GiftPopCustomWindow giftPopCustomWindow = new GiftPopCustomWindow(View.inflate(GiftListActivity.this, R.layout.pop_custom_window, null), GiftListActivity.this, UiUtils.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT);
//                        giftPopCustomWindow.showPopAtLocation(view, Gravity.BOTTOM);


                        sendGift.setVisibility(View.GONE);
                        sendFlowersLinear.setVisibility(View.VISIBLE);
                        sendFlowersNumber.setFocusable(true);
                        sendFlowersNumber.requestFocus();
                        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(sendFlowersNumber, InputMethodManager.SHOW_FORCED);

                    }
                });


            }
        });


        sendBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (sendFlowersNumber.getText().toString().equals("") || sendFlowersNumber.getText().toString().equals(null)) {
                    UiUtils.toast("请输入赠送数量");
                } else {
                    sendGift.setVisibility(View.VISIBLE);
                    sendFlowersLinear.setVisibility(View.GONE);
                    UiUtils.toast("赠送成功");
                }

            }
        });

    }
}
